let express = require('express');
let myMulter = require('../lib/middleware/myMulter');
let topicDao = require('../database/mysql/topicDao');
let verify = require('../lib/controller/verify');

let router = express.Router();

router.post('/', myMulter, async function (req, res, next) {
    let title = req.body.title;
    let discribe = req.body.discribe;
    let image = 'no';
    let interestId = req.body.fuck;
    console.log('fuck');

    let status = verify.topicVerify(req, title, discribe);
    if (status) {
        //看看有图片没,有就写入
        if (req.file) {
            image = req.file.filename;
        }

        await topicDao.insertEntries(title, discribe, image, interestId,res.session.userId);
        res.redirect('/');
    }

    res.redirect('/user_content');
})

module.exports = router;